'''
https://leetcode.cn/problems/heaters/
'''

from typing import List

class Solution:
    def findRadius(self, houses: List[int], heaters: List[int]) -> int:
        i, j = 0, 0
        m, n = len(houses), len(heaters)
        ans = 0
        while i < m:
            while j < n and abs(heaters[j + 1] - houses[i]) < abs(heaters[j] - houses[i]):
                j += 1
            ans = max(ans, abs(heaters[j] - houses[i]))
            i += 1
        return ans